package com.google.coffeeshop.dao.impl;

import java.util.List;

import com.google.coffeeshop.dao.EmployeeDAO;
import com.google.coffeeshop.entity.EmployeeDTO;
import com.googlecode.genericdao.search.Search;


public class EmployeeDAOImpl extends AbstractBaseDAOImpl<EmployeeDTO, Long> implements EmployeeDAO {
	
	@Override
	public EmployeeDTO findWorkingById(Long id){
		EmployeeDTO employee = find(id);
		if (employee != null && employee.getEndDate() == null) {
			return employee;
		}
		return null;
	}
	
	@Override
	public List<EmployeeDTO> findAllWithAscSort(){
		Search search = new Search(EmployeeDTO.class);
		search.setFirstResult(0);
		search.setMaxResults(Integer.MAX_VALUE);
		search.addSortDesc("id");
		List<EmployeeDTO> employee = this.search(search);
		if (null == employee || employee.isEmpty()){
			return null;
		}
		return employee;
	}

	@Override
	public List<EmployeeDTO> findAllWorking() {
		Search search = new Search(EmployeeDTO.class);
		search.setFirstResult(0);
		search.setMaxResults(Integer.MAX_VALUE);
		search.addFilterNull("endDate");
		List<EmployeeDTO> employee = this.search(search);
		if (null == employee || employee.isEmpty()){
			return null;
		}
		return employee;
	}
	
	

}
